#!/bin/bash
clear
if [[ "$EUID" -ne 0 ]]; then
  echo -e "\033[1;31m Anda tiada kebenaran untuk menjalankan skrip ini! \033[0m"
  exit 1
fi

TEXT='\033[30;107;2m'
GREEN='\033[92m'
YELLOW='\033[93m'
ERROR='\033[97;41m'
RESET='\033[0m'

until [[ $UserName =~ ^[a-zA-Z0-9_]+$ && $checkUser == 0 ]]; do
  read -p "Masukkan nama pengguna: " UserName
  checkUser=$(grep -w $UserName /usr/local/etc/v2ray/clients/.accounts | wc -l)
  if [[ $checkUser -ne 0 ]]; then
    echo -e "${ERROR} RALAT ${RESET}${TEXT} Nama pengguna sudah wujud! ${RESET}"
    exit 1
  fi
done
clientUUID=$(cat /usr/local/etc/v2ray/clients/.accounts | grep -w $UserName | awk '{print $3}')

cat /usr/local/etc/v2ray/vmess-tcp.json | jq 'del(.inbounds[0].settings.clients[] | select(.id == "'${clientUUID}'"))' >/usr/local/etc/v2ray/vmess-tcp.json.tmp
mv -f /usr/local/etc/v2ray/vmess-tcp.json.tmp /usr/local/etc/v2ray/vmess-tcp.json
sed -i "s|$UserNAme|d" /usr/local/etc/v2ray/clients/.accounts

systemctl restart v2ray@vmess-tcp

clear
echo
echo -e "${TEXT} ========================================================== ${RESET}"
echo -e "${TEXT} VLESS - PADAM AKAUN PENGGUNA                               ${RESET}"
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo
echo -e "${SUCCESS} INFO ${RESET}${TEXT} Berjaya memadamkan akaun pengguna ${RESET}"
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Dicipta oleh Doctype, Dikuasakan oleh Cybertize.           ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo
